package sunlight.logger;

import java.io.IOException;
import java.net.ConnectException;

public class Logger {

	public static String Type; 
	
	public static String[] AvailbleTypes = new String[]{"local", "remote"};
	
	/**
	 * @param type
	 */
	public static EventLogger getLogger(String type){
		
		try {
			if(type.equals(Logger.AvailbleTypes[0])){
				Logger.Type = Logger.AvailbleTypes[0];
				
				return new FileEventLogger();
			}
		
			if(type.equals(Logger.AvailbleTypes[1])){
				Logger.Type = Logger.AvailbleTypes[1];
				
				return new RemoteEventLogger();
			}
			
		} catch (IOException e) {
			//TODO auto generated... modify to show warning to user!
			System.out.println(e.toString());
		}
		
		return null;
	}
	
	/**
	 * @param type
	 */
	public static EventLogger getLocalLogger(String dir){
		
		Logger.Type = Logger.AvailbleTypes[0];
		
		try {
			return new FileEventLogger(dir);
			
		} catch (IOException e) {
			//TODO auto generated... modify to show warning to user!
			System.out.println(e.toString());
		}
		
		return null;
	}
	
	/**
	 * @param type
	 */
	public static EventLogger getRemoteLogger(String host, int port){
		Logger.Type = Logger.AvailbleTypes[1];
		
		try {
			return new RemoteEventLogger(host, port);
			
		}catch(ConnectException ce){
			//TODO auto generated... modify to show warning to user!
			System.out.println(ce.toString());
		} catch (IOException e) {
			//TODO auto generated... modify to show warning to user!
			System.out.println(e.toString());
		}
		
		return null;
	}

}
